home *** CD-ROM | disk | FTP | other *** search
/ Top 200 Programs / Top 200 Programs.iso / Bob8 / THOMPSON / LIBERTY / PRODUCT / TUTORIAL.EXE / MYHILO.BAS < prev    next >
BASIC Source File  |  1996-03-12  |  4KB  |  121 lines

  1.  
  2.     'MYHILO.BAS  -  Week 4 homework solution, Liberty BASIC course
  3.  
  4.     'This is a minimalistic program but it demonstrates the basics.
  5.     'You may recognize some of this code from our example program,
  6.     'but most of it is new.  Because we are using a dialog box, we
  7.     'can tab between controls, or we can use the mouse.
  8.  
  9.     'Don't use a main window
  10.     nomainwin
  11.  
  12.     'Set the width and height of our dialog box
  13.     WindowWidth = 312
  14.     WindowHeight = 145
  15.  
  16.     'Set up our controls
  17.     statictext #myhilo.instruct, "Enter your guess here:", 14, 16, 176, 20
  18.     textbox #myhilo.guessField, 14, 41, 216, 25
  19.     button #myhilo.guessNow, "Guess", [guessNow], UL, 238, 41, 50, 25
  20.     statictext #myhilo.status, "Status Line:", 14, 81, 176, 20
  21.     button #myhilo.guessNow, "About", [aboutMyhilo], UL, 238, 81, 50, 25
  22.  
  23.     'Open our program's dialog box
  24.     open "Myhilo Game -  WK4SOL" for dialog as #myhilo
  25.  
  26.     'When the user want to close our window, goto [quit]
  27.     print #myhilo, "trapclose [quit]"
  28.  
  29.     'Let's display our about-box
  30.     gosub [aboutMyhiloSub]
  31.  
  32.  
  33. [startGame] 'Start a new game of MYHILO
  34.  
  35.     guessMe = int(rnd(1)*100) + 1
  36.     print #myhilo.guessField, "-Ready for your guess-"
  37.  
  38.  
  39. [myhilo.inputLoop]   'Wait here for input event
  40.     input aVar$
  41.     goto [myhilo.inputLoop]
  42.  
  43.  
  44. [guessNow]   'Perform action for the button named 'guessNow'
  45.  
  46.     'Get the guess from our guessField
  47.     print #myhilo.guessField, "!contents?"
  48.     input #myhilo.guessField, guess
  49.  
  50.     'Now add one to the count variable to count the guesses
  51.     let count = count + 1
  52.  
  53.     'Check to see if the guess is right
  54.     if guess = guessMe then [win]
  55.  
  56.     'Check to see if the guess is too low
  57.     if guess < guessMe then status$ = "Guess higher."
  58.  
  59.     'Check to see if the guess is too high
  60.     if guess > guessMe then status$ = "Guess lower."
  61.  
  62.     print #myhilo.status, status$; " "; count; " guesses."
  63.  
  64.     'Go back and wait for more input
  65.     goto [myhilo.inputLoop]
  66.  
  67.  
  68. [win]
  69.     'Beep once and tell how many guesses it took to win
  70.     beep
  71.     print #myhilo.status, "You won in " ; count ; "! Play again."
  72.  
  73.     'Reset the count variable to zero for the next game
  74.     count = 0
  75.  
  76.     goto [startGame]
  77.  
  78.  
  79. [aboutMyhilo]  'call our about-box subroutine
  80.  
  81.     gosub [aboutMyhiloSub]
  82.     goto [myhilo.inputLoop]
  83.  
  84.  
  85. [aboutMyhiloSub]  'display information about our program
  86.  
  87.     'We could have used a NOTICE statement here, but I wanted to show
  88.     'how to do this using a modal dialog window type.
  89.  
  90.     'Set the size of our about box
  91.     WindowWidth = 368
  92.     WindowHeight = 190
  93.  
  94.     'Create statictext controls and an OK button to close the about box
  95.     statictext #about.stext1, "I have decided on a number between one", 22, 16, 312, 20
  96.     statictext #about.stext2, "and a hundred, and I want you to guess", 22, 36, 320, 20
  97.     statictext #about.stext3, "what it is.  I will tell you to guess", 22, 56, 312, 20
  98.     statictext #about.stext4, "higher or lower, and we'll count up", 22, 76, 296, 20
  99.     statictext #about.stext5, "the number of guesses you use.", 22, 96, 256, 20
  100.     button #about.OK, "OK", [closeAboutBox], UL, 278, 111, 64, 35
  101.  
  102.     'Open our about dialog box as modal
  103.     open "About Myhilo" for dialog_modal as #about
  104.  
  105.     'Use the same close code as the OK button
  106.     print #about, "trapclose [closeAboutBox]"
  107.  
  108.     return
  109.  
  110.  
  111. [closeAboutBox]   'Perform action for the button named 'OK'
  112.  
  113.     close #about
  114.     goto [myhilo.inputLoop]
  115.  
  116.  
  117. [quit] 'Quit our MYHILO program
  118.  
  119.     close #myhilo
  120.     end
  121.